import request from '@/utils/request'
import { saveAs } from 'file-saver'

// 查询所有组件
export function getAllComponent(query) {
    return request({
        url: '/admin-api/deploy/component-deploy/getAll',
        method: 'get',
        params: query
    })
}

// 查询主机管理列表
export function listComputer(query) {
    return request({
        url: '/admin-api/deploy/computer/page',
        method: 'get',
        params: query
    })
}

// 查询全部主机管理列表
export function listAllComputer(query) {
    return request({
        url: '/admin-api/deploy/computer/getAll',
        method: 'get',
        params: query
    })
}

// 查询主机管理详细
export function getComputer(query) {
    return request({
        url: '/admin-api/deploy/computer/get',
        method: 'get',
        params: query
    })
}

// 新增主机管理
export function addComputer(data) {
    return request({
        url: '/admin-api/deploy/computer/create',
        method: 'post',
        data: data
    })
}

// 修改主机管理
export function updateComputer(data) {
    return request({
        url: '/admin-api/deploy/computer/update',
        method: 'put',
        data: data
    })
}

// 删除主机管理
export function delComputer(data) {
    return request({
        url: '/admin-api/deploy/computer/delete',
        method: 'delete',
        params: data
    })
}

// 批量删除主机管理
export function delComputerList(data) {
    return request({
        url: '/admin-api/deploy/computer/delete-list',
        method: 'delete',
        params: data
    })
}

// 下载文件
export function exportComputer(data) {
    return request({
        url: '/admin-api/deploy/computer/export-excel',
        method: 'get',
        params: data,
        responseType: 'blob',
    }).then(res => {
        const blob = new Blob([res], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8" })
        saveAs(blob, decodeURIComponent('主机记录.xlsx'))
    })
}


// 技术组件的日志查询接口
export function getLogComponent(query) {
    return request({
        url: '/admin-api/log/get',
        method: 'get',
        params: query
    })
}

// 主机日志查询接口
export function getLogComputer(query) {
    return request({
        url: '/admin-api/log/get-computer',
        method: 'get',
        params: query
    })
}

// 系统日志监控 通过主机id获取分页数据
export function getSystemLogPageInfo(query) {
    return request({
        url: '/admin-api/deploy/computer/getDefaultPath',
        method: 'get',
        params: query
    })
}

// 获取所有操作系统
export function getAllOs() {
    return request({
        url: '/admin-api/deploy/computer/getOpsType',
        method: 'get'
    })
}

// 安装/admin-api/deploy/computer/installFilebeat
export function installFilebeat(data) {
    return request({
        url: '/admin-api/deploy/computer/installFilebeat?ids=' + data,
        method: 'put',
        // data
    })
}

// 系统日志 监控/批量监控
export function putSystemLogMonitor(data) {
    return request({
        url: '/admin-api/deploy/computer-log-monitor/batchStartStopMonitor',
        method: 'put',
        data
    })
}

// 主机一键监控/admin-api/deploy/component-deploy/batchStartStopMonitor=
export function putComponentDeployMonitor(data) {
    return request({
        url: '/admin-api/deploy/component-deploy/batchStartStopMonitor',
        method: 'put',
        data
    })
}